package com.hcss.sys.modulelog.task;


import com.hcss.sys.modulelog.model.HcSysModulelog;
import com.hcss.sys.modulelog.queue.ModuleLogServiceQueue;
import com.hcss.sys.modulelog.service.HcSysModulelogService;
import lombok.extern.slf4j.Slf4j;

/**
 * @描述: 模块访问日志处理线程
 * @作者: fengzhaodong
 * @创建日期: 2019-04-01 11:09
 * @公司 浙江鸿程计算机系统有限公司
 */
@Slf4j
public class ModuleLogServiceTask extends Thread{
    private final HcSysModulelogService hcSysModulelogService;
    public ModuleLogServiceTask(HcSysModulelogService hcSysModulelogService) {
        this. hcSysModulelogService =  hcSysModulelogService;
    }
    @Override
    public void run() {
        HcSysModulelog model;
        while (true) {
            try {
                sleep(1);
            } catch (InterruptedException e) {
                log.error("sleep异常中断！");
            }
            model = ModuleLogServiceQueue.getInstance().poll();
            if (model != null) {
                try {
                    hcSysModulelogService.insertModel(model);
                } catch (Exception e) {
                    log.error("日志处理异常：", e);
                }
            }
        }
    }
}
